package nsqlookupd

import (
	"log"
	"os"
	"time"
)

//这里的`` 是golang的struct tag
type Options struct {
	//verbose啰嗦的意思，是否开启啰嗦模式，开启后会输出详细的log
	Verbose   bool   `flag:"verbose"`
	//日志前缀，默认'[nsqlookupd] '
	LogPrefix string `flag:"log-prefix"`

	//TCP监听地址
	TCPAddress       string `flag:"tcp-address"`
	//HTTP监听地址
	HTTPAddress      string `flag:"http-address"`
	//当前lookupd节点的地址，默认当前系统的主机地址
	BroadcastAddress string `flag:"broadcast-address"`

	InactiveProducerTimeout time.Duration `flag:"inactive-producer-timeout"`
	TombstoneLifetime       time.Duration `flag:"tombstone-lifetime"`

	Logger Logger
}

//创建Options实例
func NewOptions() *Options {
	hostname, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}

	return &Options{
		LogPrefix:        "[nsqlookupd] ",
		TCPAddress:       "0.0.0.0:4160",
		HTTPAddress:      "0.0.0.0:4161",
		//通过hostname获取本机的地址
		//关于hostname的介绍http://wp.fungo.me/linux/what-the-hell-is-hostname.html
		BroadcastAddress: hostname,

		InactiveProducerTimeout: 300 * time.Second,
		TombstoneLifetime:       45 * time.Second,
	}
}
